package com.itheima.bakery.demos.web.model;

public enum OrderStatus {
    Pending, Processing, Shipped, Delivered, Cancelled;

    public String toDatabaseValue() {
        return this.name().toLowerCase();
    }

    public static OrderStatus fromDatabaseValue(String databaseValue) {
        if (databaseValue == null) {
            throw new IllegalArgumentException("Database value cannot be null");
        }

        // Convert the input value to uppercase to match the enum constants
        databaseValue = databaseValue.toUpperCase();

        for (OrderStatus status : values()) {
            if (status.name().equals(databaseValue)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid database value: " + databaseValue);
    }
}

